﻿using System;
using System.Collections.Generic;

namespace IceDog.Lib.Poker.PokerClient
{
    public class Launch
    {
        public static void RunGame()
        {
            var str1 = "卡莉卡牌：一种新奇的卡牌玩法";
            var str2 = "当您手里的7张牌花色一样时，您就胜利啦";
            Console.WriteLine("{0}\r\n{1}", str1, str2);
            Console.WriteLine("---------------------------------");
            string input = Helper.GetRightInput("请输入玩家数量：（2-7）：", new[] { "2", "3", "4", "5", "6", "7" });
            int choices = -1;
            try
            {
                choices = Int32.Parse(input);
            }
            catch
            {
                throw;
            }

            List<Player> playerList = new List<Player>(choices);
            for (int i = 1; i < choices + 1; i++)
            {
                Console.WriteLine("玩家 {0}，请输入您的名字(直接回车则为 player" + i + ")：", i);
                var name = "player" + i;
                var nameVal = Console.ReadLine().Trim();
                if (!string.IsNullOrEmpty(nameVal))
                {
                    name = nameVal;
                }
                playerList.Add(new Player(name));
            }

            Game game = new Game();
            game.SetPlayerList(playerList);
            int whoWin = game.PlayGame();
            if (whoWin == -1)
            {
                Console.WriteLine("抱歉，游戏发生了错误。");
            }
            else
            {
                Console.WriteLine("玩家 {0} 赢得了比赛 ^-^", playerList[whoWin].Name);
            }

        }
    }
}
